#include "addform.h"
#include "manager.h"
#include <QDomDocument>
#include <qfile.h>

AddForm::AddForm(QWidget *parent)
    : QDialog(parent)
{
	ui.setupUi(this);
	
	QFile file(Manager::data_path.path() + "DisignerList.xml");
	file.open(QFile::ReadOnly | QFile::Text);
	QDomDocument DomDoc;
	DomDoc.setContent(&file);
	QDomElement root = DomDoc.documentElement();
	QDomElement	child = root.firstChildElement("disigner");
	while(!child.isNull()){
		QString name = child.firstChildElement("name").text();
		QString dir = child.firstChildElement("dir").text();
		name_list.push_back(name);
		dir_list.push_back(dir);
		child = child.nextSiblingElement("disigner");
	}
	ui.listWidget_2->insertItems(0, name_list);

	connect(ui.pushButton_2, SIGNAL(clicked()), ui.listWidget, SLOT(clear()));

}

AddForm::~AddForm()
{

}

void AddForm::CopyFiles()
{
	QStringList all = ui.listWidget->getItems();
	QString copy_dir = dir_list[0];
	
	for(int i =0 ; i < all.count(); ++i)
	{
		QString f = all[i];
		QDir sdir(f);
		QString tdir = sdir.dirName();
		QFile::copy(f, copy_dir + tdir);	
	}			
}
